home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-20 | 1.3 KB | 46 lines | [TEXT/GEOL] |
- Item 8207938 18-Oct-89 11:22
-
- From: MUYSVASOVIC1 ER&D - J-D Muys-Vasovic
-
- To: D0220 American Zettler, Dirk Tjossen,PRT
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: Re: Object Casting…
-
- Dirk,
-
- TSortedList.Compare is declared as:
-
- FUNCTION TSortedList.Compare(item1, item2: TObject): INTEGER;
-
- Actually, the objects you are going to store in your sorted list are of a given
- class, say TFoo, declared as:
-
- TYPE
- TFoo = OBJECT(TObject)
- fBar: INTEGER;
- <many fields and methods>
- END;
-
- Now, your TSortedList.Compare (which must be overriden BTW), may be implemented
- as:
-
- FUNCTION TSortedList.Compare(item1, item2: TObject): INTEGER; OVERRIDE;
- BEGIN
- IF item1.fBar < item2.fBar THEN Compare := kALessThanB
- ELSE IF item1.fBar > item2.fBar THEN Compare := kAGreaterThanB
- ELSE Compare := kAEqualB;
- END;
-
- But this won't work: the pascal compiler will give you the "no such field in
- this object" error message: all references to item1 and item2 must first be
- typecasted to TFoo. Now, the statement according to which "item1 and item2 must
- be casted from type TObject to their actual type" is maybe a bit too strong,
- but you won't be able to compare them in any useful way if you don't.
-
- Hope that answers your question.
-
- Jean-Denis.
-
-